﻿@using zichan.BLL.StatisticsModel
@model List<TreeModel>
@{
    ViewBag.Title = "职员管理";
}
@section Pagetitle{
    @AdminCommon.PageTitle("职员管理", "")
}
@*<link href="~/Content/demo.css" rel="stylesheet" />*@
<link href="~/Content/zTreeStyle.css" rel="stylesheet" />
<script src="~/Scripts/jquery.ztree.core.js"></script>
<script src="~/Scripts/jquery.ztree.excheck.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script>
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onCheck: onCheck,
            onClick:onClick
        }
    };
    var zNodes=@Html.Raw(Json.Encode(Model));
    var code;
    function onCheck(e, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        nodes = zTree.getCheckedNodes(true);
        v = "";
        for (var i=1, l=nodes.length; i<l; i++) {
            if(!nodes[i].isParent)
            { v += nodes[i].id + ",";
                console.log(v);
             }
        }
        if (v.length > 0 ) v = v.substring(0, v.length-1);
        if($("#pIds").size()>0)
        {
            $("#pIds").val(v);
        }
        else{
            $("#nodeIds").val(v);
        }
    }
    function onClick(e,treeId,treeNode)
    {
        var ztree=$.fn.zTree.getZTreeObj("treeDemo")
        var node=ztree.getNodeByTId(treeNode.tId);
        if(node.pId!=null)
        {$(".right_bar").load("/staff/TreeAuth?id="+node.id);}
        //else{
        //    $(".right_bar").load("/staff/TreeDepartmentAuth?departmentId="+node.id)
        //}
    }

    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        var h=$(".page-container").height();
        $(".left_bar").css("height",h);
        $(".right_bar").css("height",h);
    });
</script>

<div style="height:100%;">
    <div class="left_bar">
        <div id="menuContent" class="menuContent">
            <ul id="treeDemo" class="ztree" style="margin-top:0;"></ul>
        </div>
    </div>
    <div class="right_bar" id="auth_contains">
        @Html.Action("TreeAuth", "staff", new { id = 0 })
    </div>
    <input type="hidden" id="nodeIds" />
    @*<div style="clear:both;"></div>*@
</div>
